#include <iostream>
#include <cstring>

using namespace std;

const int N = 510;
const int M = 10010;

int n, m, k;
int dist[N], backup[N];

struct Edge
{
    int a, b, c;
}edges[M];

void bellman_ford()
{
    memset(dist, 0x3f, sizeof dist);
    dist[1] = 0;

    for (int i = 0; i < k; ++i)
    {
        memcpy(backup, dist, sizeof dist);
        for (int j = 0; j < m; ++j)
        {
            int a = edges[j].a, b = edges[j].b, c = edges[j].c;
            if (dist[b] > backup[a] + c)
            {
                dist[b] = backup[a] + c;
            }
        }
    }

    if (dist[n] > 0x3f3f3f3f / 2) cout << "impossible" << endl;
    else cout << dist[n] << endl;
}

int main()
{
    cin >> n >> m >> k;
    for (int i = 0; i < m; ++i)
    {
        int a, b, c; cin >> a >> b >> c;
        edges[i].a = a, edges[i].b = b, edges[i].c = c;
    }

    bellman_ford();

    return 0;
}